import { Injectable } from '@angular/core';
import { interval, map, take } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class StreamService {
  sentences = [
    '今天天气真好',
    '我喜欢编程', 
    '学习Angular很有趣',
    '希望能成为优秀的开发者',
    '代码写得不错'
  ];

  sentences$ = interval(2000).pipe(
    take(10),
    map(() => {
      const randomIndex = Math.floor(Math.random() * this.sentences.length);
      return this.sentences[randomIndex];
    })
  );

  greetings = [
    '早上好',
    '你好',
    '晚上好',
    '再见',
    '欢迎',
    '祝你好运',
    '祝你幸福',
    '祝你健康',
    '祝你快乐',
    '祝你成功',
    '祝你发财',
  ];

  greetings$ = interval(1500).pipe(
    take(10),
    map(() => {
      const randomIndex = Math.floor(Math.random() * this.greetings.length);
      return this.greetings[randomIndex];
    })
  );

  colors = [
    '红色',
    '蓝色',
    '绿色',
    '黄色',
    '紫色',
    '橙色',
    '粉色',
    '灰色',
    '棕色',
    '黑色',
    '白色',
  ];

  colors$ = interval(500).pipe(
    take(20),
    map(() => {
      const randomIndex = Math.floor(Math.random() * this.colors.length);
      return this.colors[randomIndex];
    })
  );

  constructor() {}
}
